﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Deferred.Editor.Scene;
using Deferred.Library.Scene;

namespace Deferred.Editor.Gui.Scene
{
    public partial class DrawableObjectPanel : UserControl
    {
        private ContentChooserWindow chooserWindow;

        public DrawableObjectPanel(DrawableObject o, ContentChooserWindow chooserWindow)
        {
            InitializeComponent();

            this.chooserWindow = chooserWindow;

            drawableObjectWrapperBindingSource.DataSource = new DrawableObjectWrapper(o);
            drawableObjectBindingSource.DataSource = o;
        }

        private void browseButton_Click(object sender, EventArgs e)
        {
            chooserWindow.ValidExtensions = new List<string> {".fbx", ".x" };

            if (DialogResult.OK == chooserWindow.ShowDialog(this))
            {
                ((DrawableObject)drawableObjectBindingSource.DataSource).ModelName = chooserWindow.SelectedFileWithoutExtension;
                drawableObjectBindingSource.ResetBindings(false);
            }
        }

        private void wrapperUpDownValueChanged(object sender, EventArgs e)
        {
            drawableObjectWrapperBindingSource.EndEdit();
        }
    }
}
